<template>
  <div class="services-container">
    <div class="tit-line">
      <span class="tit-line1"></span>
      <span class="tit-line2"></span>
    </div>
    <h2 class="solve-tit">{{$t('contentDetails.ServicesNeed')}}</h2>

    <div class="services-layout">
      <!-- 左侧服务列表 -->
      <div class="services-list">
        <div
          v-for="(service, index) in services"
          :key="index"
          class="service-item"
          :class="{ active: activeService === index }"
          @click="changeService(index)"
        >
          <h3 class="service-title">{{ service.title }}</h3>
          <p class="service-en-title">{{ service.enTitle }}</p>
        </div>
      </div>

      <!-- 右侧内容展示 -->
      <div class="service-content">
        <div v-if="
          services.length > 0 &&
          activeService !== null &&
          activeService >= 0 &&
          activeService < services.length &&
          services[activeService]"
             class="content-wrapper">
          <h3 class="content-title">{{ services[activeService].title }}</h3>
          <p class="content-desc">{{ services[activeService].description }}</p>
          <a :href="services[activeService].detailLink " class="learn-more">
            {{$t('buttonInfo.seeMore')}}
            <span class="more-icon"></span>
          </a>
        </div>
        <div v-else class="empty-content">
          {{$t('contentDetails.loading')}}
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    services: {
      type: Array,
      default: () => []
    }
  },
  data(){
    return{
      activeService: 0,
    }
  },
  computed: {
    baseUrl() {
      return process.env.VUE_APP_BASE_API
    }
  },
  methods: {
    changeService(index) {
      this.activeService = index;
    },
  }
}
</script>


<style scoped lang="scss">
.services-container {
  max-width: 1200px;
  margin: 80px auto;
  padding: 0 20px;
}

.project-tit {
  text-align: left;
  margin-bottom: 50px;
}

.tit-line {
  display: flex;
  justify-content: left;
  margin-bottom: 20px;
}

.tit-line1, .tit-line2 {
  height: 8px;
  background: #fe3231;
  border-radius: 10px;
}

.tit-line1 {
  width: 60px;
}

.tit-line2 {
  width: 10px;
  margin-left: 10px;
}

.solve-tit {
  font-size: 30px;
  font-weight: bold;
  color: #333;
  margin-bottom: 15px;
  text-align: left;
}

.services-layout {
  display: flex;
  margin-top: 40px;
  overflow: hidden;
}

.services-list {
  width: 35%;
}

.service-item {
  padding: 15px 25px;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-bottom: 16px;
  background-color: #eeeeee;

  &:hover {
    background: #f0f0f0;
  }

  &.active {
    background-color: #fe3231;
    position: relative;

    .service-title {
      color: #fff !important;
    }

    .service-en-title {
      color: #fff;
    }
  }
}

.service-title {
  font-size: 18px;
  font-weight: 550;
  color: #333;
  margin-bottom: 5px;
  transition: color 0.3s;
}

.service-en-title {
  font-size: 14px;
  color: #666;
}

.service-item.active .service-title,
.service-item:hover .service-title {
  color: #fe3231;
}

.service-content {
  width: 65%;
  background: #fff;
  padding: 20px;
  min-height: 400px;
  position: relative;
}

.content-wrapper {
  animation: fadeIn 0.5s ease;
  padding: 16px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.content-title {
  font-size: 24px;
  color: #333;
  margin-bottom: 40px;
  padding-bottom: 10px;
  text-align: center;
}

.content-desc {
  font-size: 16px;
  line-height: 1.8;
  color: #666;
  margin-bottom: 30px;
  height: 260px; /* 设置固定高度 */
  overflow: hidden; /* 超出部分隐藏 */
  display: -webkit-box;
  -webkit-line-clamp: 10; /* 显示5行 */
  -webkit-box-orient: vertical;
  text-overflow: ellipsis; /* 超出部分显示省略号 */
}

.learn-more {
  position: absolute;
  bottom: 60px;
  left: 30px;
  display: inline-flex;
  align-items: center;
  padding: 16px 40px;
  border: 1px solid #d62828;
  color: #333;
  text-decoration: none;
  transition: all 0.3s ease;
  font-size: 16px;

  &:hover {
    color: #d62828;
    border-color: #fe3231;

    .more-icon {
      background-position: right center;
    }
  }
}

.more-icon {
  display: inline-block;
  width: 20px;
  height: 20px;
  margin-left: 8px;
  background: url('~@/assets/asl_images/more.png') no-repeat left center;
  background-size: contain;
  transition: all 0.3s ease;
}

.empty-content {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #999;
  font-size: 18px;
}

/* 媒体查询：为小屏幕设备添加移动端样式 */
@media (max-width: 768px) {
  .services-layout {
    flex-direction: column; /* 垂直排列 */
  }

  .services-list {
    width: 100%;
    margin-bottom: 20px;
  }

  .service-content {
    width: 100%;
  }

  .service-item {
    padding: 10px 15px;
    margin-bottom: 10px;
  }

  .service-title {
    font-size: 16px;
  }

  .service-en-title {
    font-size: 12px;
  }

  .content-title {
    font-size: 20px;
    margin-bottom: 20px;
  }

  .content-desc {
    font-size: 14px;
    -webkit-line-clamp: 8; /* 调整行数 */
  }

  .learn-more {
    position: static;
    bottom: auto;
    left: auto;
    padding: 12px 20px;
    margin-top: 10px;
  }
}

@media (max-width: 480px) {
  .services-container {
    margin: 40px auto;
    padding: 0 10px;
  }

  .solve-tit {
    font-size: 20px;
    margin-bottom: 10px;
  }

  .service-item {
    padding: 8px 10px;
    margin-bottom: 8px;
  }

  .service-title {
    font-size: 14px;
  }

  .service-en-title {
    font-size: 10px;
  }

  .content-title {
    font-size: 18px;
    margin-bottom: 15px;
  }

  .content-desc {
    font-size: 12px;
    -webkit-line-clamp: 6; /* 调整行数 */
  }

  .learn-more {
    padding: 10px 15px;
    font-size: 14px;
  }
}
</style>
